﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="CC98.Metro.Pages.Account.AccountList"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    IsTabStop="false"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:CC98.Metro.Pages.Account"
    xmlns:common="using:CC98.Metro.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:cnv="using:CC98.Xaml.Converters"
    xmlns:ctl="using:CC98.Metro.Controls"
    mc:Ignorable="d">

    <Page.Resources>
        <CollectionViewSource x:Name="itemsViewSource" Source="{Binding Items}" IsSourceGrouped="True" />
        <cnv:BoolToStringConverter x:Key="authStateConverter" TrueString="{Binding Source={StaticResource resHelper}, Path=Resources.LoggedIn}"
                                   FalseString="{Binding Source={StaticResource resHelper}, Path=Resources.LoggedOut}" />
        <cnv:IntToVisibility x:Key="appBarButtonVisibilityConverter" CollapsedInt="-1"  />
    </Page.Resources>

    <Page.BottomAppBar>
        <AppBar>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <StackPanel Orientation="Horizontal"  Grid.Column="0" >
                    <Button x:Name="btnNewUser" Style="{StaticResource AddAppBarButtonStyle}" Click="btnNewUser_Click" />
                    <Button x:Name="btnSwitch" Style="{StaticResource YesAppBarButtonStyle}" Click="btnSwitch_Click"
                            Visibility="{Binding ElementName=itemGridView, Path=SelectedIndex, Converter={StaticResource appBarButtonVisibilityConverter}}"/>
                    <Button x:Name="btnViewUser" Style="{StaticResource EditAppBarButtonStyle}" Click="btnViewUser_Click"
                            Visibility="{Binding ElementName=itemGridView, Path=SelectedIndex, Converter={StaticResource appBarButtonVisibilityConverter}}"/>
                    <Button x:Name="btnRemove" Style="{StaticResource RemoveAppBarButtonStyle}" Click="btnRemove_Click"
                            Visibility="{Binding ElementName=itemGridView, Path=SelectedIndex, Converter={StaticResource appBarButtonVisibilityConverter}}"/>
                </StackPanel>
                <Button x:Name="btnNetworkSetting" Grid.Column="2" Style="{StaticResource SettingsAppBarButtonStyle}" />
            </Grid>
        </AppBar>
    </Page.BottomAppBar>
    
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <!-- Background -->
        <ctl:ParallaxBackground x:Name="background" Grid.RowSpan="2" Grid.ColumnSpan="2" ImageSource="../../Assets/Images/Background/BlueStripe.png" />
        <!-- Back button and page title -->
        <Grid Grid.Column="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Uid="SwitchAccount" x:Name="pageTitle" Grid.Column="1" Text="{StaticResource AppName}" Style="{StaticResource PageHeaderTextStyle}"/>
        </Grid>
        <!-- User account protrait -->
        <ctl:UserAccountPortrait Grid.Column="1" Margin="0,0,50,0" />
        
        <!-- Horizontal scrolling grid used in most view states -->
        <GridView
            x:Name="itemGridView"
            AutomationProperties.AutomationId="ItemsGridView"
            AutomationProperties.Name="Items"
            TabIndex="1"
            Grid.Row="1"
            Grid.ColumnSpan="2"
            Margin="0,-4,0,0"
            Padding="116,0,116,46"
            SelectionMode="Single"
            ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
            ItemTemplate="{StaticResource AccountListItemTemplate}">
            <GridView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Key, Converter={StaticResource authStateConverter}}" Style="{StaticResource SubheaderTextStyle}" />
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </GridView.GroupStyle>
        </GridView>

        <!-- Vertical scrolling list only used when snapped -->
        <ListView
            x:Name="itemListView"
            AutomationProperties.AutomationId="ItemsListView"
            AutomationProperties.Name="Items"
            TabIndex="1"
            Grid.Row="1"
            Visibility="Collapsed"
            Margin="0,-10,0,0"
            Padding="10,0,0,60"
            ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
            ItemTemplate="{StaticResource Standard80ItemTemplate}"/>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="96,0,86,56"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!--
                    The back button and title have different styles when snapped, and the list representation is substituted
                    for the grid displayed in all other view states
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
    
</common:LayoutAwarePage>
